<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: seo_url.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.' );

define('MODULE_SEO_URL_INDEX_TEXT_DESCRIPTION', 'Der Indexierungsdienst erstellt die SUMA-freundlichen Direct URLs f&uuml;rr Ihren Shop.');

define('MODULE_SEO_URL_INDEX_TEXT_TITLE', 'seo:url Creator');
define('MODULE_SEO_URL_INDEX_STATUS_DESC','Modulstatus');

define('MODULE_SEO_URL_URL_LENGHT_TITLE', 'Kurze URLs?');
define('MODULE_SEO_URL_URL_LENGHT_DESC','Sollen kurze URL\'s genutzt werden?');

define('MODULE_SEO_URL_INDEX_STATUS_TITLE','Status');

define('MODULE_SEO_URL_INDEX_LANGUAGEURL_TITLE','Sprachabh&auml;ngige URLs<br />../de/.. | ../en/..');
define('MODULE_SEO_URL_INDEX_LANGUAGEURL_DESC','Die suchmaschinenfreundlichen URLs werden sprachabh&auml;ngig kodiert');

define('MODULE_SEO_URL_CATEGORY_SPACER_TITLE','Kategorie-URL Trennzeichen');
define('MODULE_SEO_URL_CATEGORY_SPACER_DESC','Wie sollen die URL\'s zusammengesetzt werden?<br />Bsp.: <b>"/"</b> - shop.de/erste/zweite/dritte/<br />Bsp.: <b>"-"</b> - shop.de/erste-zweite-dritte/');

define('MODULE_SEO_URL_INDEX_AVOIDDUPLICATECONTENT_TITLE','Doppelten Content vermeiden');
define('MODULE_SEO_URL_INDEX_AVOIDDUPLICATECONTENT_DESC','Aktivieren Sie diese Option um Doppelten Content zu vermeiden (Code 301 Redirect).');

define('MODULE_SEO_URL_INDEX_CREATENEWINDEX_TITLE','Indexierung durchführen');
define('MODULE_SEO_URL_INDEX_CREATENEWINDEX_DESC','Aktivieren Sie diese Option um beim Speichern alle Seiten neu zu indexieren.');

define('INDEX_START','<strong>Indexierung starten</strong>');
define('INDEX_START_DESCRIPTION','Klicken Sie auf "OK" um die Einstellungen zu speichern. Ist die Option "Indexierung durchführen" auf "True" gesetzt, kann dieser Vorgang einige Zeit in Anspruch nehmen. Brechen Sie diese Operation keinesfalls ab!');

class seo_url {
	var $code, $title, $description, $enabled, $seourl, $db;

	function __construct() {
		global $order, $db;

		$this->code = 'seo_url';
		$this->title = MODULE_SEO_URL_INDEX_TEXT_TITLE;
		$this->description = MODULE_SEO_URL_INDEX_TEXT_DESCRIPTION;
		$this->sort_order = MODULE_SEO_URL_INDEX_SORT_ORDER;
		$this->enabled = ((MODULE_SEO_URL_INDEX_STATUS == 'True') ? true : false);
		$this->lenght = ((MODULE_SEO_URL_URL_LENGHT == 'True') ? true : false);
		$this->db = $db;
	}

    function process($file) {
		require_once(DIR_FS_INC.'inc.seo_url.php');
  		!$seo_url ? $seo_url = new SeoUrl() : false;

		if($_REQUEST['startindex']=='true')
			$seo_url->createSeoDBTable();

    }

    function display() {
		$pulldown_option[0]['text']='Ja';
		$pulldown_option[0]['id']='true';
		$pulldown_option[1]['text']='Nein';
		$pulldown_option[1]['id']='false';

		return array('text' => 	'<br /><strong>Indexierung durchf&uuml;hren?</strong><br />
								Sollen alle Seiten beim Klick auf "OK" indiziert werden?<br />'.
                            	draw_pull_down_menu('startindex',$pulldown_option,'Ja').'<br /><br />'.
 								button(BUTTON_REVIEW_APPROVE).'&nbsp;' .
                            button_link(BUTTON_CANCEL, href_link(FILENAME_MODULE_EXPORT, 'set='.$_GET['set'].'&module=seo_urlindex')));
    }

    function check() {
    	if (!isset($this->_check)) {
	      $check = $this->db->db_query("SELECT configuration_value FROM ".TABLE_CONFIGURATION." WHERE configuration_key = 'MODULE_SEO_URL_INDEX_STATUS'");
	      $this->_check = $check->_numOfRows;
	    }
	    return $this->_check;
    }

    function install() {
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SEO_URL_INDEX_STATUS', 'True',  '111', '1', 'cfg_select_option(array(\'True\', \'False\'), ', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SEO_URL_INDEX_LANGUAGEURL', 'False',  '111', '2', 'cfg_select_option(array(\'True\', \'False\'), ', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SEO_URL_CATEGORY_SPACER', '/',  '111', '3', 'cfg_select_option(array(\'/\', \'-\'), ', NOW())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SEO_URL_INDEX_AVOIDDUPLICATECONTENT', 'True',  '111', '4', 'cfg_select_option(array(\'True\', \'False\'), ', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SEO_URL_URL_LENGHT', 'True',  '111', '5', 'cfg_select_option(array(\'True\', \'False\'), ', now())");

		// Tabellenstruktur commerce_seo_url anlegen, wenn noch nicht vorhanden
		$createTableQuery =	"CREATE TABLE IF NOT EXISTS `".TABLE_SEO_URL."` (
							`url_md5` varchar(32) NOT NULL default '',
							`url_text` varchar(255) NOT NULL default '',
							`products_id` int(11) default NULL,
							`categories_id` int(11) default NULL,
							`blog_id` int(11) default NULL,
							`blog_cat` int(11) default NULL,
							`content_group` int(11) default NULL,
							`language_id` int(11) NOT NULL default '0',
							PRIMARY KEY  (`url_md5`),
							KEY `url_text` (`url_text`,`products_id`));";
		$this->db->db_query($createTableQuery);
	}

    function remove() {
    	$this->db->db_query("DELETE FROM ".TABLE_CONFIGURATION." WHERE configuration_key IN ('".implode("', '", $this->keys())."')");
    }

    function keys() {
      	return array('MODULE_SEO_URL_INDEX_STATUS',
			      	'MODULE_SEO_URL_INDEX_LANGUAGEURL',
			      	'MODULE_SEO_URL_URL_LENGHT',
			      	'MODULE_SEO_URL_CATEGORY_SPACER',
			      	'MODULE_SEO_URL_INDEX_AVOIDDUPLICATECONTENT');
    }
}